<#assign title ="文章录入">
<#include "/include/layout.ftl">
	<link href="${contextPath}/js/umeditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
<#macro css>
</#macro>
<#macro js>
	<script src="${contextPath}/js/umeditor/umeditor.config.js" charset="utf-8"></script>
	<script src="${contextPath}/js/umeditor/umeditor.js" charset="utf-8"></script>
</#macro>
<#macro body>
<#import "/include/select.ftl" as items>
	<section class="content-header">
      <h1>
        ${title}
        <small>添加</small>
      	<a class="btn btn-default pull-right back" href="javascript:;"><i class="fa fa-reply"></i> 返回</a>
      </h1>
    </section>
    <section class="content">
		<div class="box box-info">
			<div class="row">
				<div class="col-sm-12">
			        <div class="box-header with-border">
			        	参数信息
			        </div>
			        <form action="${contextPath}/article/save" method="post" id="documentForm" class="form-horizontal">
			          <input type="hidden" name="id" value="${data.id}" />
		              <div class="box-body">
		                <div class="form-group">
		                  <label class="col-sm-2 control-label">排序编号:</label>
		                  <div class="col-sm-3">
		                    <input name="orderno" value="${data.orderno}" class="form-control"  placeholder="排序编号" required digits="true" maxlength=8 />
		                  </div>
		                </div>
		                <div class="form-group">
		                  <label class="col-sm-2 control-label">文章类型:</label>
		                  <div class="col-sm-3">
		                    <@items.select id="typeid" list=typelist key="id" text="title" value="${data.typeid}" class="" /> 
		                  </div>
		                </div>
		                <div class="form-group">
		                  <label class="col-sm-2 control-label">文章标题:</label>
		                  <div class="col-sm-3">
		                    <input name="title" value="${data.title}" class="form-control"  placeholder="文章标题" required maxlength=50 />
		                  </div>
		                </div>
		                <div class="form-group">
		                  <label class="col-sm-2 control-label">内容:</label>
		                  <div class="col-sm-8">
		                  	<textarea id="umeditor" name="umeditor" class="form-control" placeholder="内容" maxlength="1000" style="resize: none;width:100%;height:322px;">${data.content}</textarea>
		                  </div>
		                </div>
		                
		              </div>
		              <div class="box-footer">
		              	<div class="col-sm-2"></div>
		              	 <div class="col-sm-6">
		              	 	<a class="btn btn-default" id="reset" ><i class="fa fa-rotate-left"></i> 重置</a>
		              	 	<a class="btn btn-info submit"><i class="fa fa-save"></i> 确定</a>
			             </div>
		              </div>
		            </form>
		         </div>
	        </div>
	    </div>
    </section>
	<script type="text/javascript">
		var um = UM.getEditor('umeditor');
		$(function(){
			//表单提交
			$(".submit").click(function(){
				if (validateForm()) {
					var content = um.getContent();
					var typeid = $("#typeid").val();
					if(!typeid){
						layer.msg("文章类型不能为空！", {icon: 0});
						return false;
					}
					if (content) {
						var options = {
								data:{"content":content},
								success: showResponse
							}
						$("#documentForm").ajaxSubmit(options);
						return false;
						
					} else {
						layer.msg("请输入通知内容！", {icon: 0});
					}
				}
			})
		
		})
		
		//ajax 返回
		function showResponse(responseText, statusText) {
			var code = responseText.code;
			var msg = responseText.msg;
			if (code == "1") {
				  layer.alert(msg,{icon: 1}, function(index){
					  location.href="${contextPath}/article/index.html";
				 	  layer.close(index);
				});  
			} else {
				layer.msg(msg, {icon: 2});
			}
		}	
		
		//表单验证
		function validateForm(){
		   return $("#documentForm").validate().form();
		}
	</script>
</#macro>